$.ajax({
	url: "/api/complex/MyNote",
	type: "get",
	data: {
		sid: App.get("loginer.sid")
	},
	success: function(result) {
		console.log(result);
		App.set('$Cache_Note_get_types', result);
	},
	error: function(e) {
		console.log(e);
	}
});

$.ajax({
	url: "/api/complex/MyNote",
	type: "get",
	data: {
		sid: App.get("loginer.sid"),
		datatype: true
	},
	success: function(result) {
		console.log(result);
		for (var i = 0; i < result.length; i++) {
			var str;
			if (result[i].src) {
				// str = "<div class='noteitem'><div class='item'><div class='time'>" + (new Date(parseInt(result[i].createtime))).toLocaleDateString() + "</div><div class='type'>" + result[i].typename + "</div></div><div class='item'><img src='" + result[i].src + "'></div><div class='item'>s=vt</div><div class='item'><input type='text' class='text' /><button>发布</button></div>";
				str = "<div class='noteitem'><div class='item'><div class='time'>" + (new Date(parseInt(result[i].createtime))).toLocaleDateString() + "</div><div class='type'>" + result[i].typename + "</div></div><div class='item'><img src='" + result[i].src + "'></div><div class='item'>" + result[i].text + "</div>";
			} else {
				// str = "<div class='noteitem'><div class='item'><div class='time'>" + (new Date(parseInt(result[i].createtime))).toLocaleDateString() + "</div><div class='type'>" + result[i].typename + "</div></div><div class='item'>" + result[i].text + "</div><div class='item'><input type='text' class='text' /><button>发布</button></div>";
				str = "<div class='noteitem'><div class='item'><div class='time'>" + (new Date(parseInt(result[i].createtime))).toLocaleDateString() + "</div><div class='type'>" + result[i].typename + "</div></div><div class='item'>" + result[i].text + "</div>";
			}
			// console.log(str);
			$("#list" + ((i % 3) + 1)).append(str);
		};
	},
	error: function(e) {
		console.log(e);
	}
});



function getMynote(obj) {
	console.log("hehe");
}

$("[name='addtype']").click(function() {
	var name = App.get("$Cache_Note_type_new");
	if (name) {
		$.ajax({
			url: "/api/complex/MyNote",
			type: "post",
			data: data = {
				datatype: 1,
				sid: App.get("loginer.sid"),
				id: new Date().getTime(),
				name: name,
				num: 0
			},
			success: function(r) {
				var str = "<div data=" + data.id + " class='item' onclick='getMynote(this)'>" + data.name + "(" + data.num + ")</div>";
				$(".typebox").append(str);
				var str2 = "<option value=" + data.id + ">" + data.name + "</option>";
				$("[name='chosebox']").append(str2);
				myConfirm("添加分类成功！！！");
				$("input").val("");
				// console.log(r);
			},
			error: function(e) {
				console.log(e);
			}
		})
	} else {
		myConfirm("请先输入分类名称！！！");
	}
});


var savedir;
$("#createnote").click(function() {
	if ($("[name='newnote']").val()) {
		var src = App.get("savedir");
		var data = {};
		$.ajax({
			url: "/api/complex/MyNote",
			type: "post",
			data: data = {
				id: new Date().getTime(),
				sid: App.get("loginer.sid"),
				typeid: $("[name='chosebox']").val(),
				title: "",
				text: $("[name='newnote']").val(),
				url: "",
				src: src,
				typename: $("[name='chosebox']").find("option:selected").text()
			},
			success: function(r) {
				// console.log(r);
				$.ajax({
					url: "/api/complex/MyNote",
					type: "put",
					data: {
						id: data.typeid
					},
					success: function(result) {
						// console.log(result);
						$("textarea").val("");
						$(".imgset").removeClass("focus");
						savedir = "";
						myConfirm("笔记已添加！！！", function() {
							location.reload();
						}, function() {
							location.reload();
						});
					},
					error: function(error) {
						console.log(error);
					}
				})
			},
			error: function(e) {
				console.log(e);
			}
		})
	} else {
		myConfirm("请填写好您的笔记！！！");
	}
});
// 上传图片
function upfile(obj) {
	var savedir = fileupload(obj);
	App.set("savedir", savedir);
	console.log(savedir)
	if (savedir) {
		$(".imgset").addClass("focus");
		$("#upimg")[0].src = savedir;
	};
}